// pages/list_content/list_content.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    contents: [],
    id: '',
    initialState: false
  },

  /**
   * 页面跳转
   */
  nav: function(e) {
    var _this = this,
      index = e.currentTarget.dataset.index,
      contents = _this.data.contents,
      structure_id = contents[index].id,
      subject_id = contents[index].subject_id,
      stage_id = contents[index].stage_id;
    wx.navigateTo({
      url: '/pages/aiPaper/aiPaper?structure_id=' + structure_id + '&subject_id=' + subject_id + '&stage_id=' + stage_id,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    wx.setNavigationBarTitle({
      title: options.name
    })
    this.setData({
      id: options.id,
      gradeId: options.grade_id
    })
    var that = this;
    var subjectId = that.data.id;
    var stageId = that.data.gradeId;
    wx.request({
      url: app.globalData.URL + '/kmapping/WebAppAjax/getStructureList?level=1&token=' + wx.getStorageSync('token'),
      dataType: 'json',
      method: 'GET',
      data: {
        stage_id: stageId,
        subject_id: subjectId
      },
      success: function(res) {
        var _res = res.data;
        if (_res.error_code == 0) {
          var _contents = _res.data;
          that.setData({
            'contents': _contents,
            'initialState': true
          })
        } else {
          that.setData({
            'initialState': true
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})